Error processing request

Parameters

CONTENT_LENGTH0
REQUEST_METHODGET
REQUEST_URI/revision/file+size?V=22
QUERY_STRINGV=22
CONTENT_TYPE
DOCUMENT_URI/revision/file+size
DOCUMENT_ROOT/var/www/nikit/nikit/nginx/../docroot
SCGI1
SERVER_PROTOCOLHTTP/1.1
HTTPSon
REMOTE_ADDR172.70.100.57
REMOTE_PORT59062
SERVER_PORT4443
SERVER_NAMEwiki.tcl-lang.org
HTTP_HOSTwiki.tcl-lang.org
HTTP_CONNECTIONKeep-Alive
HTTP_ACCEPT_ENCODINGgzip, br
HTTP_X_FORWARDED_FOR3.144.4.221
HTTP_CF_RAY883a9c34aa8f8f4d-ORD
HTTP_X_FORWARDED_PROTOhttps
HTTP_CF_VISITOR{"scheme":"https"}
HTTP_ACCEPT*/*
HTTP_USER_AGENTMozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; [email protected])
HTTP_REFERERhttp://wiki.tcl.tk/revision/file+size?V=22
HTTP_CF_CONNECTING_IP3.144.4.221
HTTP_CDN_LOOPcloudflare
HTTP_CF_IPCOUNTRYUS

Body


Error

Unknow state transition: LINE -> END

-code

1

-level

0

-errorstack

INNER {returnImm {Unknow state transition: LINE -> END} {}} CALL {my render_wikit {file size} \ \ \ \ :\ \ \ '''file\ size'''\ ''name''\n\nReturns\ a\ decimal\ string\ giving\ the\ size\ of\ file\ ''name''\ in\ bytes.\nIf\ the\ file\ doesn't\ exist\ or\ its\ size\ cannot\ be\ queried\ then\ an\ error\ is\ generated.\n\n----\n<<discussion>>\nBefore\ Tcl\ 8.4a4,\ '''file\ size'''\ would\ actually\ throw\ an\ error\ on\ a\ file\ larger\ than\ 2gb.\nNow\ it\ works,\ and\ returns\ the\ correct\ value\ for\ such\ 'large\ files'.\n\n\[AMG\],\ 16\ Apr\ 2011:\ 32-bit\ MinGW\ builds\ of\ Tcl\ get\ the\ wrong\ \[\[file\ size\]\]\ for\ 2+\ gigabyte\ files\ \[https://sourceforge.net/tracker/?func=detail&aid=3288345&group_id=10894&atid=110894\].\n\n----\n'''file\ size'''\ must\ return\ the\ complete\ size\ of\ a\ file\ including\ any\ data\nwhich\ the\ OS\ might\ not\ yet\ have\ written\ to\ disk.\nOn\ Unix\ this\ is\ easy,\ but\ on\ Windows,\ Tcl\ actually\ has\ to\ force\ the\ OS\ to\ flush\ all\ buffers\nbefore\ returning\ the\ information.\ \ (Of\ course\ all\ of\ this\ happens\ behind\ the\ scenes).\n\n----\n\[MB\]\ The\ following\ is\ a\ package\ to\ convert\ a\ file\ size\ in\ bytes\ into\ a\ \nhuman\ readable\ form.\ For\ example,\ if\ one\ has\ a\ 10\ 000\ bytes\ file\ :\n\ \ hrfilesize::bytestohr\ 10000\nreturns\ \"9.8\ Kbytes\"\n\nNotice\ that\ the\ following\ package\ is\ based\ on\ the\ Tcllib\ package\n\"bigfloat\",\ so\ that\ it\ can\ handle\ file\ sizes\ up\ to\ the\ epta\ byte.\n=====\n\ \ \ \ #\n\ \ \ \ #\ hrfilesize--\n\ \ \ \ #\ \ \ Convert\ a\ size\ in\ byte\ into\ a\ human\ readable\ form.\n\ \ \ \ #\ \ \ http://en.wikipedia.org/wiki/Byte\n\ \ \ \ #\ \ \ http://en.wikipedia.org/wiki/File_size\n\ \ \ \ #\ \ \ http://physics.nist.gov/cuu/Units/binary.html\n\ \ \ \ #\n\ \ \ \ #\ \ \ Copyright:\ Michael\ Baudin,\ 2008,\ [email protected]\n\ \ \ \ #\n\n\ \ \ \ package\ provide\ hrfilesize\ 1.0\n\n\ \ \ \ namespace\ eval\ hrfilesize\ \ \{\n\ \ \ \ \ \ \ \ #\ System\ used\ to\ convert\ from\ bytes\ into\ the\ new\ unit\n\ \ \ \ \ \ \ \ variable\ unitsystem\n\ \ \ \ \ \ \ \ #\ Format\ used\ to\ convert\ from\ real\ file\ size\ to\ string\n\ \ \ \ \ \ \ \ variable\ realformat\n\ \ \ \ \ \ \ \ #\ Integer\ to\ convert\ from\ 1\ byte\ (binary\ or\ decimal)\ into\ the\ new\ unit\n\ \ \ \ \ \ \ \ variable\ kilobytes\n\ \ \ \ \ \ \ \ #\ This\ is\ a\ map\ from\ the\ power\ to\ the\ unit\ name\n\ \ \ \ \ \ \ \ variable\ powertounitmap\n\ \ \ \ \ \ \ \ #\ Maximum\ available\ power\n\ \ \ \ \ \ \ \ variable\ powermax\ 6\n\ \ \ \ \ \ \ \ #\ Component\ used\ to\ process\ the\ integers\n\ \ \ \ \ \ \ \ variable\ integerpackage\n\ \ \ \ \}\n\n\ \ \ \ #\n\ \ \ \ #\ hrfilesize::bytestohr\ --\n\ \ \ \ #\ \ \ Returns\ a\ string\ containing\ an\ human-readable\ form\n\ \ \ \ #\ \ \ representing\ the\ given\ size\ in\ bytes\ by\ computing\n\ \ \ \ #\ \ \ the\ size\ in\ the\ suitable\ units\ :\n\ \ \ \ #\ \ \ -\ bytes,\n\ \ \ \ #\ \ \ -\ kilobytes,\n\ \ \ \ #\ \ \ -\ megabytes,\n\ \ \ \ #\ \ \ -\ gigabytes,\n\ \ \ \ #\ \ \ -\ terabytes,\n\ \ \ \ #\ \ \ -\ petabytes,\n\ \ \ \ #\ \ \ -\ exabytes.\n\ \ \ \ #\ Example:\n\ \ \ \ #\ \ \ If\ one\ have\ a\ 10\ 000\ bytes\ file\ :\n\ \ \ \ #\ \ \ \ \ hrfilesize::bytestohr\ 10000\n\ \ \ \ #\ \ \ returns\ \"10.0\ KB\"\n\ \ \ \ #\ Arguments:\n\ \ \ \ #\ \ \ size:\ the\ size\ in\ bytes\n\ \ \ \ #\ \ \ -realformat\ value\ :\ the\ format\ used\ to\ convert\ from\ the\ full\ real\ size\n\ \ \ \ #\ \ \ \ \ \ to\ a\ sexy\ short\ real.\ Defaults\ to\ \"%.1f\"\n\ \ \ \ #\ \ \ -unit\ value\ :\ the\ unit\ system\ to\ convert\ from\ bytes.\n\ \ \ \ #\ \ \ \ \ \ If\ \"value\"\ is\ \"binary\"\ then\ one\ kilobyte\ is\ made\ of\ 1024\ bytes.\n\ \ \ \ #\ \ \ \ \ \ If\ \"value\"\ is\ \"decimal\"\ then\ one\ kilobyte\ is\ made\ of\ 1000\ bytes.\n\ \ \ \ #\ \ \ \ \ \ The\ default\ unit\ system\ is\ decimal.\n\ \ \ \ #\ \ \ -integerpackage\ value\ :\ the\ package\ to\ process\ integer\ values\n\ \ \ \ #\ \ \ \ \ \ If\ \"value\"\ is\ \"Tcl\"\ then\ the\ integers\ are\ processed\ with\ Tcl\ \"expr\"\ command\n\ \ \ \ #\ \ \ \ \ \ If\ \"value\"\ is\ \"bigfloat\"\ then\ the\ integers\ are\ processed\ with\ Tcl\ lib\ package\ \"bigfloat\"\n\ \ \ \ #\n\ \ \ \ proc\ hrfilesize::bytestohr\ \{size\ args\}\ \{\n\ \ \ \ \ \ \ \ #\n\ \ \ \ \ \ \ \ #\ Process\ options\n\ \ \ \ \ \ \ \ #\n\ \ \ \ \ \ \ \ foreach\ \{key\ value\}\ \$args\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ hrfilesize::configure\ \$key\ \$value\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ #\n\ \ \ \ \ \ \ \ #\ Compute\ the\ size\ in\ the\ new\ unit\n\ \ \ \ \ \ \ \ #\n\ \ \ \ \ \ \ \ set\ newsize\ \[hrfilesize::newsize\ \$size\]\n\ \ \ \ \ \ \ \ set\ y\ \[lindex\ \$newsize\ 0\]\n\ \ \ \ \ \ \ \ set\ power\ \[lindex\ \$newsize\ 1\]\n\ \ \ \ \ \ \ \ #\ Limits\ the\ power\ to\ 6\n\ \ \ \ \ \ \ \ if\ \{\$power>\$hrfilesize::powermax\}\ then\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ error\ \"File\ size\ larger\ than\ the\ maximum\ available\ size\ unit\ (power\ :\ \$power)\"\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ array\ set\ unitarray\ \$hrfilesize::powertounitmap\n\ \ \ \ \ \ \ \ set\ unit\ \$unitarray(\$power)\n\ \ \ \ \ \ \ \ set\ shortdouble\ \[format\ \$hrfilesize::realformat\ \$y\]\n\ \ \ \ \ \ \ \ set\ result\ \"\$shortdouble\ \$unit\"\n\ \ \ \ \ \ \ \ return\ \$result\n\ \ \ \ \}\n\ \ \ \ #\n\ \ \ \ #\ hrfilesize::configure\ --\n\ \ \ \ #\ \ \ Configure\ the\ conversion\ system\ depending\ on\ the\ couples\ (key,value)\n\ \ \ \ #\ \ \ given\ in\ the\ list\ args.\n\ \ \ \ #\ Arguments:\n\ \ \ \ #\ \ \ -realformat\ value\ :\ the\ format\ used\ to\ convert\ from\ the\ full\ real\ size\n\ \ \ \ #\ \ \ \ \ \ to\ a\ sexy\ short\ real.\ Defaults\ to\ \"%.1f\"\n\ \ \ \ #\ \ \ -unit\ value\ :\ the\ unit\ system\ to\ convert\ from\ bytes.\n\ \ \ \ #\ \ \ \ \ \ If\ \"value\"\ is\ \"binary\"\ then\ one\ kilobyte\ is\ made\ of\ 1024\ bytes.\n\ \ \ \ #\ \ \ \ \ \ If\ \"value\"\ is\ \"decimal\"\ then\ one\ kilobyte\ is\ made\ of\ 1000\ bytes.\n\ \ \ \ #\ \ \ -integerpackage\ value\ :\ the\ package\ to\ process\ integer\ values\n\ \ \ \ #\ \ \ \ \ \ If\ \"value\"\ is\ \"Tcl\"\ then\ the\ integers\ are\ processed\ with\ Tcl\ \"expr\"\ command\n\ \ \ \ #\ \ \ \ \ \ If\ \"value\"\ is\ \"bigfloat\"\ then\ the\ integers\ are\ processed\ with\ Tcl\ lib\ package\ \"bigfloat\"\n\ \ \ \ #\n\ \ \ \ proc\ hrfilesize::configure\ \{args\}\ \{\n\ \ \ \ \ \ \ \ #\n\ \ \ \ \ \ \ \ #\ Process\ options\n\ \ \ \ \ \ \ \ #\n\ \ \ \ \ \ \ \ foreach\ \{key\ value\}\ \$args\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ switch\ --\ \$key\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \"-realformat\"\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ set\ hrfilesize::realformat\ \$value\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \"-unit\"\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ set\ hrfilesize::unitsystem\ \$value\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \"-integerpackage\"\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ set\ hrfilesize::integerpackage\ \$value\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ default\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ error\ \"Unknown\ key\ \$key\"\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ #\n\ \ \ \ \ \ \ \ #\ Configure\ internal\ settings\ depending\ on\ the\ unit\ system\n\ \ \ \ \ \ \ \ #\n\ \ \ \ \ \ \ \ switch\ --\ \$hrfilesize::unitsystem\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \"binary\"\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ set\ hrfilesize::kilobytes\ 1024\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ set\ hrfilesize::powertounitmap\ \[list\ 0\ \"B\"\ \\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 1\ \"KiB\"\ \\\n\ \ \ \ \ \ \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\ \ -\ the\ power\ of\ the\ kilobytes\ multiple,\n\ \ \ \ #\ \ \ that\ is,\ computes\ newsize\ and\ power\ such\ that\ :\n\ \ \ \ #\ \ \ \ \ size\ =\ y\ x\ 1000^power\ if\ the\ unit\ is\ decimal\n\ \ \ \ #\ \ \ \ \ size\ =\ y\ x\ 1024^power\ if\ the\ unit\ is\ binary\n\ \ \ \ #\n\ \ \ \ proc\ hrfilesize::newsize\ \{size\}\ \{\n\ \ \ \ \ \ \ \ switch\ --\ \$hrfilesize::integerpackage\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \"Tcl\"\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ set\ result\ \[hrfilesize::newsize_tcl\ \$size\]\n\ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \ \ \ \ \"bigfloat\"\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ set\ result\ \[hrfilesize::newsize_bifloat\ \$size\]\n\ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \ \ \ \ default\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ error\ \"Unknown\ integer\ package\ \$hrfilesize::integerpackage\"\n\ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ return\ \$result\n\ \ \ \ \}\n\ \ \ \ #\n\ \ \ \ #\ hrfilesize::newsize_tcl\ --\n\ \ \ \ #\ \ \ Compute\ the\ new\ size\ based\ on\ Tcl\ \"expr\"\ command.\n\ \ \ \ #\n\ \ \ \ #\ Limitations\n\ \ \ \ #\ \ \ Tcl\ string\ to\ integer\ conversion\ is\ based\ on\ the\ C\ integer\ long\ type,\n\ \ \ \ #\ \ \ so\ that\ the\ maximum\ integer\ is\ approximately\ 2\ GB\ if\ we\ suppose\ that\n\ \ \ \ #\ \ \ the\ long\ integer\ is\ based\ on\ 32\ bits.\n\ \ \ \ #\ \ \ If\ the\ given\ size\ is\ greater\ that\ 2\ GB,\ the\ Tcl\ \"expr\"\ command\n\ \ \ \ #\ \ \ will\ fail\ to\ process\ the\ integer.\n\ \ \ \ #\n\ \ \ \ proc\ hrfilesize::newsize_tcl\ \{size\}\ \{\n\ \ \ \ \ \ \ \ set\ y\ \[expr\ \{double(\$size)\}\]\n\ \ \ \ \ \ \ \ set\ power\ 0\n\ \ \ \ \ \ \ \ while\ \{\$y\ >=\ \$hrfilesize::kilobytes\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ incr\ power\n\ \ \ \ \ \ \ \ \ \ \ \ set\ y\ \[expr\ \{\$y\ /\ double(\$hrfilesize::kilobytes)\}\]\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ return\ \[list\ \$y\ \$power\]\n\ \ \ \ \}\n\ \ \ \ #\n\ \ \ \ #\ hrfilesize::newsize_bifloat\ --\n\ \ \ \ #\ \ \ Compute\ the\ new\ size\ based\ on\ the\ bigfloat\ package.\n\ \ \ \ #\n\ \ \ \ proc\ hrfilesize::newsize_bifloat\ \{size\}\ \{\n\ \ \ \ \ \ \ \ package\ require\ math::bigfloat\n\ \ \ \ \ \ \ \ set\ y\ \[math::bigfloat::fromstr\ \$size\]\n\ \ \ \ \ \ \ \ set\ y\ \[math::bigfloat::int2float\ \$y\]\n\ \ \ \ \ \ \ \ set\ kb\ \[math::bigfloat::fromstr\ \$hrfilesize::kilobytes\]\n\ \ \ \ \ \ \ \ set\ kb\ \[math::bigfloat::int2float\ \$kb\]\n\ \ \ \ \ \ \ \ set\ power\ 0\n\ \ \ \ \ \ \ \ set\ compare\ \[math::bigfloat::compare\ \$y\ \$kb\]\n\ \ \ \ \ \ \ \ while\ \{\$compare>=0\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ incr\ power\n\ \ \ \ \ \ \ \ \ \ \ \ set\ y\ \[math::bigfloat::div\ \$y\ \$kb\]\n\ \ \ \ \ \ \ \ \ \ \ \ set\ compare\ \[math::bigfloat::compare\ \$y\ \$kb\]\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ set\ y\ \[math::bigfloat::todouble\ \$y\]\n\ \ \ \ \ \ \ \ return\ \[list\ \$y\ \$power\]\n\ \ \ \ \}\n\ \ \ \ #\n\ \ \ \ #\ compare\ --\n\ \ \ \ #\ \ \ Compare\ two\ files\ sizes\ represented\ in\ human\ readable\ form,\ and\n\ \ \ \ #\ \ \ return\ -1\ if\ size1\ in\ less\ than\ size2,\ 0\ if\ size1\ and\n\ \ \ \ #\ \ \ size2\ are\ equal\ or\ 1\ if\ size2\ is\ greater\ than\ size2.\n\ \ \ \ #\ \ \ The\ two\ file\ sizes\ may\ be\ in\ different\ units\ but\ in\ the\ same\n\ \ \ \ #\ \ \ unit\ system,\ that\ is,\ the\ two\ values\ in\ decimal\ units,\ or\ the\ two\n\ \ \ \ #\ \ \ values\ in\ binary\ units.\n\ \ \ \ #\ Arguments:\n\ \ \ \ #\ \ \ size1,\ size2:\ the\ size\ of\ the\ first\ file/directory\ which\ is\ a\ list\ of\ two\ items\n\ \ \ \ #\ \ \ \ \ as\ returned\ by\ \"bytestohr\"\ :\n\ \ \ \ #\ \ \ \ \ -\ the\ first\ item\ is\ a\ real\ value\ representing\ the\ size,\n\ \ \ \ #\ \ \ \ \ -\ the\ second\ item\ is\ the\ unit.\n\ \ \ \ #\ \ \ -unit\ value\ :\ the\ unit\ system\ to\ convert\ from\ bytes.\n\ \ \ \ #\ \ \ \ \ \ If\ \"value\"\ is\ \"binary\"\ then\ one\ kilobyte\ is\ made\ of\ 1024\ bytes.\n\ \ \ \ #\ \ \ \ \ \ If\ \"value\"\ is\ \"decimal\"\ then\ one\ kilobyte\ is\ made\ of\ 1000\ bytes.\n\ \ \ \ #\ \ \ \ \ \ The\ default\ unit\ system\ is\ decimal.\n\ \ \ \ #\ \ \ -integerpackage\ value\ :\ the\ package\ to\ process\ integer\ values\n\ \ \ \ #\ \ \ \ \ \ If\ \"value\"\ is\ \"Tcl\"\ then\ the\ integers\ are\ processed\ with\ Tcl\ \"expr\"\ command\n\ \ \ \ #\ \ \ \ \ \ If\ \"value\"\ is\ \"bigfloat\"\ then\ the\ integers\ are\ processed\ with\ Tcl\ lib\ package\ \"bigfloat\"\n\ \ \ \ #\n\ \ \ \ proc\ hrfilesize::compare\ \{size1\ size2\ args\}\ \{\n\ \ \ \ \ \ \ \ #\n\ \ \ \ \ \ \ \ #\ Process\ options\n\ \ \ \ \ \ \ \ #\n\ \ \ \ \ \ \ \ foreach\ \{key\ value\}\ \$args\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ hrfilesize::configure\ \$key\ \$value\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ #\n\ \ \ \ \ \ \ \ #\ Get\ values\ and\ units\n\ \ \ \ \ \ \ \ #\n\ \ \ \ \ \ \ \ set\ size1value\ \[lindex\ \$size1\ 0\]\n\ \ \ \ \ \ \ \ set\ size1unit\ \[lindex\ \$size1\ 1\]\n\ \ \ \ \ \ \ \ set\ size2value\ \[lindex\ \$size2\ 0\]\n\ \ \ \ \ \ \ \ set\ size2unit\ \[lindex\ \$size2\ 1\]\n\ \ \ \ \ \ \ \ #\n\ \ \ \ \ \ \ \ #\ The\ two\ values\ are\ in\ the\ same\ unit\ :\n\ \ \ \ \ \ \ \ #\ compare\ the\ values.\n\ \ \ \ \ \ \ \ #\n\ \ \ \ \ \ \ \ if\ \{\$size1unit==\$size2unit\}\ then\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ if\ \{\$size1value\ <\ \$size2value\}\ then\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ set\ compare\ -1\n\ \ \ \ \ \ \ \ \ \ \ \ \}\ elseif\ \{\$size1value\ ==\ \$size2value\}\ then\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ set\ compare\ 0\n\ \ \ \ \ \ \ \ \ \ \ \ \}\ else\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ set\ compare\ 1\n\ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \}\ else\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ #\n\ \ \ \ \ \ \ \ \ \ \ \ #\ Compare\ the\ units\n\ \ \ \ \ \ \ \ \ \ \ \ #\n\ \ \ \ \ \ \ \ \ \ \ \ set\ unit1index\ \[lsearch\ \$hrfilesize::powertounitmap\ \$size1unit\]\n\ \ \ \ \ \ \ \ \ \ \ \ set\ unit2index\ \[lsearch\ \$hrfilesize::powertounitmap\ \$size2unit\]\n\ \ \ \ \ \ \ \ \ \ \ \ if\ \{\$unit1index==-1\ ||\ \$unit2index==-1\}\ then\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ error\ \"The\ current\ unit\ system\ \$hrfilesize::unitsystem\ does\ not\ match\ the\ given\ units\ for\ \$size1\ and\ \$size2.\"\n\ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \ \ \ \ if\ \{\$unit1index\ <\ \$unit2index\}\ then\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ set\ compare\ -1\n\ \ \ \ \ \ \ \ \ \ \ \ \}\ else\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ set\ compare\ 1\n\ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ return\ \$compare\n\ \ \ \ \}\n\ \ \ \ #\n\ \ \ \ #\ Automatic\ configuration\ of\ the\ package\ at\ loading.\n\ \ \ \ #\n\ \ \ \ hrfilesize::configure\ -unit\ \"decimal\"\n\ \ \ \ hrfilesize::configure\ -realformat\ \"%.1f\"\n\ \ \ \ hrfilesize::configure\ -integerpackage\ \"bigfloat\"\n======\n\nAnd\ here\ are\ the\ tests.\n======\n\ \ \ \ package\ require\ tcltest\n\ \ \ \ namespace\ import\ tcltest::test\n\ \ \ \ lappend\ ::auto_path\ .\n\ \ \ \ package\ require\ hrfilesize\ 1.0\n\n\ \ \ \ #\n\ \ \ \ #\ Caution\ !\n\ \ \ \ #\ \ \ Use\ constant\ string\ values\ instead\ of\ using\ Tcl\ expr\ in\ integer\n\ \ \ \ #\ \ \ values\ only.\n\ \ \ \ #\ \ \ This\ is\ because\ Tcl\ string\ to\ integer\ conversion\ is\ based\ on\n\ \ \ \ #\ \ \ the\ C\ integer\ long\ type,\ so\ that\ the\ maximum\ integer\ is\ approximately\n\ \ \ \ #\ \ \ 2\ GB.\n\ \ \ \ #\n\ \ \ \ tcltest::test\ hrfilesize-binary-1\ \{50\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ 50\ -unit\ binary\]\n\ \ \ \ \}\ \{50.0\ B\}\n\ \ \ \ tcltest::test\ hrfilesize-binary-2\ \{10\ 000\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ 10000\ -unit\ binary\]\n\ \ \ \ \}\ \{9.8\ KiB\}\n\ \ \ \ tcltest::test\ hrfilesize-binary-3\ \{10\ 000\ 000\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ 10000000\ -unit\ binary\]\n\ \ \ \ \}\ \{9.5\ MiB\}\n\ \ \ \ tcltest::test\ hrfilesize-binary-4\ \{10\ 000\ 000\ 000\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ 10000000000\ -unit\ binary\]\n\ \ \ \ \}\ \{9.3\ GiB\}\n\ \ \ \ tcltest::test\ hrfilesize-binary-5\ \{10\ 000\ 000\ 000\ 000\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ 10000000000000\ -unit\ binary\]\n\ \ \ \ \}\ \{9.1\ TiB\}\n\ \ \ \ tcltest::test\ hrfilesize-binary-6\ \{Pib\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ 10000000000000000\ -unit\ binary\]\n\ \ \ \ \}\ \{8.9\ PiB\}\n\ \ \ \ tcltest::test\ hrfilesize-binary-7\ \{Eib\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ 10000000000000000000\ -unit\ binary\]\n\ \ \ \ \}\ \{8.7\ EiB\}\n\ \ \ \ tcltest::test\ hrfilesize-binary-8\ \{1024\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ 1024\ -unit\ binary\]\n\ \ \ \ \}\ \{1.0\ KiB\}\n\ \ \ \ tcltest::test\ hrfilesize-binary-9\ \{1025\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ 1025\ -unit\ binary\]\n\ \ \ \ \}\ \{1.0\ KiB\}\n\ \ \ \ tcltest::test\ hrfilesize-binary-10\ \{0\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ 0\ -unit\ binary\]\n\ \ \ \ \}\ \{0.0\ B\}\n\ \ \ \ tcltest::test\ hrfilesize-binary-11\ \{1\ Mbyte\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ \[expr\ \{1024*1024\}\]\ -unit\ binary\]\n\ \ \ \ \}\ \{1.0\ MiB\}\n\n\ \ \ \ tcltest::test\ hrfilesize-decimal-1\ \{50\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ 50\ -unit\ decimal\]\n\ \ \ \ \}\ \{50.0\ B\}\n\ \ \ \ tcltest::test\ hrfilesize-decimal-2\ \{10000\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ 10000\ -unit\ decimal\]\n\ \ \ \ \}\ \{10.0\ KB\}\n\ \ \ \ tcltest::test\ hrfilesize-decimal-3\ \{10000000\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ 10000000\ -unit\ decimal\]\n\ \ \ \ \}\ \{10.0\ MB\}\n\ \ \ \ tcltest::test\ hrfilesize-decimal-4\ \{10000000000\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ 10000000000\ -unit\ decimal\]\n\ \ \ \ \}\ \{10.0\ GB\}\n\ \ \ \ tcltest::test\ hrfilesize-decimal-5\ \{10000000000000\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ 10000000000000\ -unit\ decimal\]\n\ \ \ \ \}\ \{10.0\ TB\}\n\ \ \ \ tcltest::test\ hrfilesize-decimal-6\ \{Pib\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ 10000000000000000\ -unit\ decimal\]\n\ \ \ \ \}\ \{10.0\ PB\}\n\ \ \ \ tcltest::test\ hrfilesize-decimal-7\ \{Eib\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ 10000000000000000000\ -unit\ decimal\]\n\ \ \ \ \}\ \{10.0\ EB\}\n\ \ \ \ tcltest::test\ hrfilesize-decimal-8\ \{1024\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ 1024\ -unit\ decimal\]\n\ \ \ \ \}\ \{1.0\ KB\}\n\ \ \ \ tcltest::test\ hrfilesize-decimal-9\ \{1025\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ 1025\ -unit\ decimal\]\n\ \ \ \ \}\ \{1.0\ KB\}\n\ \ \ \ tcltest::test\ hrfilesize-decimal-10\ \{0\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ 0\ -unit\ decimal\]\n\ \ \ \ \}\ \{0.0\ B\}\n\ \ \ \ tcltest::test\ hrfilesize-decimal-11\ \{1\ Mbyte\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ \[expr\ \{1024*1024\}\]\ -unit\ decimal\]\n\ \ \ \ \}\ \{1.1\ MB\}\n\n\ \ \ \ tcltest::test\ hrfilesize-error-1\ \{what\ happens\ if\ we\ give\ a\ real\ value\ ?\}\ \{\n\ \ \ \ \ \ \ \ set\ errflag\ \[catch\ \{hrfilesize::bytestohr\ 50.\}\ errmsg\]\n\ \ \ \ \ \ \ \ set\ result\ \[list\ \$errflag\ \$errmsg\]\n\ \ \ \ \}\ \{1\ \{first\ argument\ is\ not\ an\ integer\}\}\n\ \ \ \ tcltest::test\ hrfilesize-error-2\ \{what\ happens\ if\ we\ give\ a\ size\ larger\ than\ the\ larger\ unit\ ?\}\ \{\n\ \ \ \ \ \ \ \ set\ errflag\ \[catch\ \{hrfilesize::bytestohr\ 10000000000000000000000\ -unit\ decimal\}\ errmsg\]\n\ \ \ \ \ \ \ \ set\ result\ \[list\ \$errflag\ \$errmsg\]\n\ \ \ \ \}\ \{1\ \{File\ size\ larger\ than\ the\ maximum\ available\ size\ unit\ (power\ :\ 7)\}\}\n\ \ \ \ tcltest::test\ hrfilesize-compare-1\ \{two\ sizes\ in\ B\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::compare\ \"1.0\ B\"\ \"2.0\ B\"\]\n\ \ \ \ \}\ \{-1\}\n\ \ \ \ tcltest::test\ hrfilesize-compare-2\ \{two\ sizes\ in\ B\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::compare\ \"1.0\ B\"\ \"1.0\ B\"\]\n\ \ \ \ \}\ \{0\}\n\ \ \ \ tcltest::test\ hrfilesize-compare-3\ \{two\ sizes\ in\ B\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::compare\ \"2.0\ B\"\ \"1.0\ B\"\]\n\ \ \ \ \}\ \{1\}\n\ \ \ \ tcltest::test\ hrfilesize-compare-4\ \{size1\ in\ B,\ size2\ in\ KB\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::compare\ \"1.0\ B\"\ \"1.0\ KB\"\]\n\ \ \ \ \}\ \{-1\}\n\ \ \ \ tcltest::test\ hrfilesize-compare-5\ \{size1\ in\ B,\ size2\ in\ KB\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::compare\ \"1.0\ KB\"\ \"1.0\ B\"\]\n\ \ \ \ \}\ \{1\}\n\ \ \ \ tcltest::test\ hrfilesize-compare-6\ \{size1\ in\ KB,\ size2\ in\ MB\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::compare\ \"1.0\ KB\"\ \"1.0\ MB\"\]\n\ \ \ \ \}\ \{-1\}\n\ \ \ \ tcltest::test\ hrfilesize-compare-7\ \{size1\ in\ KB,\ size2\ in\ KiB\}\ \{\n\ \ \ \ \ \ \ \ set\ errflag\ \[catch\ \{hrfilesize::compare\ \"1.0\ KB\"\ \"1.0\ KiB\"\}\ errmsg\]\n\ \ \ \ \ \ \ \ set\ res\ \[list\ \$errflag\ \$errmsg\]\n\ \ \ \ \}\ \{1\ \{The\ current\ unit\ system\ decimal\ does\ not\ match\ the\ given\ units\ for\ 1.0\ KB\ and\ 1.0\ KiB.\}\}\n\ \ \ \ tcltest::test\ hrfilesize-compare-8\ \{size1\ in\ KiB,\ size2\ in\ MiB\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::compare\ \"1.0\ KiB\"\ \"1.0\ MiB\"\ -unit\ binary\]\n\ \ \ \ \}\ \{-1\}\n\ \ \ \ tcltest::test\ hrfilesize-compare-8\ \{size1\ in\ KiB,\ size2\ in\ MiB\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::compare\ \"1.0\ MiB\"\ \"1.0\ KiB\"\ -unit\ binary\]\n\ \ \ \ \}\ \{1\}\n\n\ \ \ \ ::tcltest::cleanupTests\n======\n\n----\n<<discussion>>\n**See\ also**\n\ \ \ *\ \[file\]\n\ \ \ *\ \[file\ exists\]\n\ \ \ *\ \[file\ stat\]\n\ \ \ *\ \[directory\ size\]\n\ \ \ *\ \[Narrow\ formatting\]\n\ \ \ *\ \[hrbytesize\]\n<<categories>>\ Tcl\ syntax\ help\ |\ Command\ |\ Introspection\ |\ File regexp2} CALL {my render {file size} \ \ \ \ :\ \ \ '''file\ size'''\ ''name''\n\nReturns\ a\ decimal\ string\ giving\ the\ size\ of\ file\ ''name''\ in\ bytes.\nIf\ the\ file\ doesn't\ exist\ or\ its\ size\ cannot\ be\ queried\ then\ an\ error\ is\ generated.\n\n----\n<<discussion>>\nBefore\ Tcl\ 8.4a4,\ '''file\ size'''\ would\ actually\ throw\ an\ error\ on\ a\ file\ larger\ than\ 2gb.\nNow\ it\ works,\ and\ returns\ the\ correct\ value\ for\ such\ 'large\ files'.\n\n\[AMG\],\ 16\ Apr\ 2011:\ 32-bit\ MinGW\ builds\ of\ Tcl\ get\ the\ wrong\ \[\[file\ size\]\]\ for\ 2+\ gigabyte\ files\ \[https://sourceforge.net/tracker/?func=detail&aid=3288345&group_id=10894&atid=110894\].\n\n----\n'''file\ size'''\ must\ return\ the\ complete\ size\ of\ a\ file\ including\ any\ data\nwhich\ the\ OS\ might\ not\ yet\ have\ written\ to\ disk.\nOn\ Unix\ this\ is\ easy,\ but\ on\ Windows,\ Tcl\ actually\ has\ to\ force\ the\ OS\ to\ flush\ all\ buffers\nbefore\ returning\ the\ information.\ \ (Of\ course\ all\ of\ this\ happens\ behind\ the\ scenes).\n\n----\n\[MB\]\ The\ following\ is\ a\ package\ to\ convert\ a\ file\ size\ in\ bytes\ into\ a\ \nhuman\ readable\ form.\ For\ example,\ if\ one\ has\ a\ 10\ 000\ bytes\ file\ :\n\ \ hrfilesize::bytestohr\ 10000\nreturns\ \"9.8\ Kbytes\"\n\nNotice\ that\ the\ following\ package\ is\ based\ on\ the\ Tcllib\ package\n\"bigfloat\",\ so\ that\ it\ can\ handle\ file\ sizes\ up\ to\ the\ epta\ byte.\n=====\n\ \ \ \ #\n\ \ \ \ #\ hrfilesize--\n\ \ \ \ #\ \ \ Convert\ a\ size\ in\ byte\ into\ a\ human\ readable\ form.\n\ \ \ \ #\ \ \ http://en.wikipedia.org/wiki/Byte\n\ \ \ \ #\ \ \ http://en.wikipedia.org/wiki/File_size\n\ \ \ \ #\ \ \ http://physics.nist.gov/cuu/Units/binary.html\n\ \ \ \ #\n\ \ \ \ #\ \ \ Copyright:\ Michael\ Baudin,\ 2008,\ [email protected]\n\ \ \ \ #\n\n\ \ \ \ package\ provide\ hrfilesize\ 1.0\n\n\ \ \ \ namespace\ eval\ hrfilesize\ \ \{\n\ \ \ \ \ \ \ \ #\ System\ used\ to\ convert\ from\ bytes\ into\ the\ new\ unit\n\ \ \ \ \ \ \ \ variable\ unitsystem\n\ \ \ \ \ \ \ \ #\ Format\ used\ to\ convert\ from\ real\ file\ size\ to\ string\n\ \ \ \ \ \ \ \ variable\ realformat\n\ \ \ \ \ \ \ \ #\ Integer\ to\ convert\ from\ 1\ byte\ (binary\ or\ decimal)\ into\ the\ new\ unit\n\ \ \ \ \ \ \ \ variable\ kilobytes\n\ \ \ \ \ \ \ \ #\ This\ is\ a\ map\ from\ the\ power\ to\ the\ unit\ name\n\ \ \ \ \ \ \ \ variable\ powertounitmap\n\ \ \ \ \ \ \ \ #\ Maximum\ available\ power\n\ \ \ \ \ \ \ \ variable\ powermax\ 6\n\ \ \ \ \ \ \ \ #\ Component\ used\ to\ process\ the\ integers\n\ \ \ \ \ \ \ \ variable\ integerpackage\n\ \ \ \ \}\n\n\ \ \ \ #\n\ \ \ \ #\ hrfilesize::bytestohr\ --\n\ \ \ \ #\ \ \ Returns\ a\ string\ containing\ an\ human-readable\ form\n\ \ \ \ #\ \ \ representing\ the\ given\ size\ in\ bytes\ by\ computing\n\ \ \ \ #\ \ \ the\ size\ in\ the\ suitable\ units\ :\n\ \ \ \ #\ \ \ -\ bytes,\n\ \ \ \ #\ \ \ -\ kilobytes,\n\ \ \ \ #\ \ \ -\ megabytes,\n\ \ \ \ #\ \ \ -\ gigabytes,\n\ \ \ \ #\ \ \ -\ terabytes,\n\ \ \ \ #\ \ \ -\ petabytes,\n\ \ \ \ #\ \ \ -\ exabytes.\n\ \ \ \ #\ Example:\n\ \ \ \ #\ \ \ If\ one\ have\ a\ 10\ 000\ bytes\ file\ :\n\ \ \ \ #\ \ \ \ \ hrfilesize::bytestohr\ 10000\n\ \ \ \ #\ \ \ returns\ \"10.0\ KB\"\n\ \ \ \ #\ Arguments:\n\ \ \ \ #\ \ \ size:\ the\ size\ in\ bytes\n\ \ \ \ #\ \ \ -realformat\ value\ :\ the\ format\ used\ to\ convert\ from\ the\ full\ real\ size\n\ \ \ \ #\ \ \ \ \ \ to\ a\ sexy\ short\ real.\ Defaults\ to\ \"%.1f\"\n\ \ \ \ #\ \ \ -unit\ value\ :\ the\ unit\ system\ to\ convert\ from\ bytes.\n\ \ \ \ #\ \ \ \ \ \ If\ \"value\"\ is\ \"binary\"\ then\ one\ kilobyte\ is\ made\ of\ 1024\ bytes.\n\ \ \ \ #\ \ \ \ \ \ If\ \"value\"\ is\ \"decimal\"\ then\ one\ kilobyte\ is\ made\ of\ 1000\ bytes.\n\ \ \ \ #\ \ \ \ \ \ The\ default\ unit\ system\ is\ decimal.\n\ \ \ \ #\ \ \ -integerpackage\ value\ :\ the\ package\ to\ process\ integer\ values\n\ \ \ \ #\ \ \ \ \ \ If\ \"value\"\ is\ \"Tcl\"\ then\ the\ integers\ are\ processed\ with\ Tcl\ \"expr\"\ command\n\ \ \ \ #\ \ \ \ \ \ If\ \"value\"\ is\ \"bigfloat\"\ then\ the\ integers\ are\ processed\ with\ Tcl\ lib\ package\ \"bigfloat\"\n\ \ \ \ #\n\ \ \ \ proc\ hrfilesize::bytestohr\ \{size\ args\}\ \{\n\ \ \ \ \ \ \ \ #\n\ \ \ \ \ \ \ \ #\ Process\ options\n\ \ \ \ \ \ \ \ #\n\ \ \ \ \ \ \ \ foreach\ \{key\ value\}\ \$args\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ hrfilesize::configure\ \$key\ \$value\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ #\n\ \ \ \ \ \ \ \ #\ Compute\ the\ size\ in\ the\ new\ unit\n\ \ \ \ \ \ \ \ #\n\ \ \ \ \ \ \ \ set\ newsize\ \[hrfilesize::newsize\ \$size\]\n\ \ \ \ \ \ \ \ set\ y\ \[lindex\ \$newsize\ 0\]\n\ \ \ \ \ \ \ \ set\ power\ \[lindex\ \$newsize\ 1\]\n\ \ \ \ \ \ \ \ #\ Limits\ the\ power\ to\ 6\n\ \ \ \ \ \ \ \ if\ \{\$power>\$hrfilesize::powermax\}\ then\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ error\ \"File\ size\ larger\ than\ the\ maximum\ available\ size\ unit\ (power\ :\ \$power)\"\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ array\ set\ unitarray\ \$hrfilesize::powertounitmap\n\ \ \ \ \ \ \ \ set\ unit\ \$unitarray(\$power)\n\ \ \ \ \ \ \ \ set\ shortdouble\ \[format\ \$hrfilesize::realformat\ \$y\]\n\ \ \ \ \ \ \ \ set\ result\ \"\$shortdouble\ \$unit\"\n\ \ \ \ \ \ \ \ return\ \$result\n\ \ \ \ \}\n\ \ \ \ #\n\ \ \ \ #\ hrfilesize::configure\ --\n\ \ \ \ #\ \ \ Configure\ the\ conversion\ system\ depending\ on\ the\ couples\ (key,value)\n\ \ \ \ #\ \ \ given\ in\ the\ list\ args.\n\ \ \ \ #\ Arguments:\n\ \ \ \ #\ \ \ -realformat\ value\ :\ the\ format\ used\ to\ convert\ from\ the\ full\ real\ size\n\ \ \ \ #\ \ \ \ \ \ to\ a\ sexy\ short\ real.\ Defaults\ to\ \"%.1f\"\n\ \ \ \ #\ \ \ -unit\ value\ :\ the\ unit\ system\ to\ convert\ from\ bytes.\n\ \ \ \ #\ \ \ \ \ \ If\ \"value\"\ is\ \"binary\"\ then\ one\ kilobyte\ is\ made\ of\ 1024\ bytes.\n\ \ \ \ #\ \ \ \ \ \ If\ \"value\"\ is\ \"decimal\"\ then\ one\ kilobyte\ is\ made\ of\ 1000\ bytes.\n\ \ \ \ #\ \ \ -integerpackage\ value\ :\ the\ package\ to\ process\ integer\ values\n\ \ \ \ #\ \ \ \ \ \ If\ \"value\"\ is\ \"Tcl\"\ then\ the\ integers\ are\ processed\ with\ Tcl\ \"expr\"\ command\n\ \ \ \ #\ \ \ \ \ \ If\ \"value\"\ is\ \"bigfloat\"\ then\ the\ integers\ are\ processed\ with\ Tcl\ lib\ package\ \"bigfloat\"\n\ \ \ \ #\n\ \ \ \ proc\ hrfilesize::configure\ \{args\}\ \{\n\ \ \ \ \ \ \ \ #\n\ \ \ \ \ \ \ \ #\ Process\ options\n\ \ \ \ \ \ \ \ #\n\ \ \ \ \ \ \ \ foreach\ \{key\ value\}\ \$args\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ switch\ --\ \$key\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \"-realformat\"\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ set\ hrfilesize::realformat\ \$value\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \"-unit\"\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ set\ hrfilesize::unitsystem\ \$value\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \"-integerpackage\"\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ set\ hrfilesize::integerpackage\ \$value\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ default\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \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 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ 6\ \"EB\"\ \\\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \]\n\ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \ \ \ \ default\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ error\ \"Unknown\ unit\ \$unit\"\n\ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ return\ \"\"\n\ \ \ \ \}\n\ \ \ \ #\n\ \ \ \ #\ hrfilesize::newsize\ --\n\ \ \ \ #\ \ \ Returns\ a\ couple\ made\ of\ two\ items\ :\n\ \ \ \ #\ \ \ -\ the\ size\ in\ the\ new\ unit\ (y),\n\ \ \ \ #\ \ \ -\ the\ power\ of\ the\ kilobytes\ multiple,\n\ \ \ \ #\ \ \ that\ is,\ computes\ newsize\ and\ power\ such\ that\ :\n\ \ \ \ #\ \ \ \ \ size\ =\ y\ x\ 1000^power\ if\ the\ unit\ is\ decimal\n\ \ \ \ #\ \ \ \ \ size\ =\ y\ x\ 1024^power\ if\ the\ unit\ is\ binary\n\ \ \ \ #\n\ \ \ \ proc\ hrfilesize::newsize\ \{size\}\ \{\n\ \ \ \ \ \ \ \ switch\ --\ \$hrfilesize::integerpackage\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \"Tcl\"\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ set\ result\ \[hrfilesize::newsize_tcl\ \$size\]\n\ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \ \ \ \ \"bigfloat\"\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ set\ result\ \[hrfilesize::newsize_bifloat\ \$size\]\n\ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \ \ \ \ default\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ error\ \"Unknown\ integer\ package\ \$hrfilesize::integerpackage\"\n\ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ return\ \$result\n\ \ \ \ \}\n\ \ \ \ #\n\ \ \ \ #\ hrfilesize::newsize_tcl\ --\n\ \ \ \ #\ \ \ Compute\ the\ new\ size\ based\ on\ Tcl\ \"expr\"\ command.\n\ \ \ \ #\n\ \ \ \ #\ Limitations\n\ \ \ \ #\ \ \ Tcl\ string\ to\ integer\ conversion\ is\ based\ on\ the\ C\ integer\ long\ type,\n\ \ \ \ #\ \ \ so\ that\ the\ maximum\ integer\ is\ approximately\ 2\ GB\ if\ we\ suppose\ that\n\ \ \ \ #\ \ \ the\ long\ integer\ is\ based\ on\ 32\ bits.\n\ \ \ \ #\ \ \ If\ the\ given\ size\ is\ greater\ that\ 2\ GB,\ the\ Tcl\ \"expr\"\ command\n\ \ \ \ #\ \ \ will\ fail\ to\ process\ the\ integer.\n\ \ \ \ #\n\ \ \ \ proc\ hrfilesize::newsize_tcl\ \{size\}\ \{\n\ \ \ \ \ \ \ \ set\ y\ \[expr\ \{double(\$size)\}\]\n\ \ \ \ \ \ \ \ set\ power\ 0\n\ \ \ \ \ \ \ \ while\ \{\$y\ >=\ \$hrfilesize::kilobytes\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ incr\ power\n\ \ \ \ \ \ \ \ \ \ \ \ set\ y\ \[expr\ \{\$y\ /\ double(\$hrfilesize::kilobytes)\}\]\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ return\ \[list\ \$y\ \$power\]\n\ \ \ \ \}\n\ \ \ \ #\n\ \ \ \ #\ hrfilesize::newsize_bifloat\ --\n\ \ \ \ #\ \ \ Compute\ the\ new\ size\ based\ on\ the\ bigfloat\ package.\n\ \ \ \ #\n\ \ \ \ proc\ hrfilesize::newsize_bifloat\ \{size\}\ \{\n\ \ \ \ \ \ \ \ package\ require\ math::bigfloat\n\ \ \ \ \ \ \ \ set\ y\ \[math::bigfloat::fromstr\ \$size\]\n\ \ \ \ \ \ \ \ set\ y\ \[math::bigfloat::int2float\ \$y\]\n\ \ \ \ \ \ \ \ set\ kb\ \[math::bigfloat::fromstr\ \$hrfilesize::kilobytes\]\n\ \ \ \ \ \ \ \ set\ kb\ \[math::bigfloat::int2float\ \$kb\]\n\ \ \ \ \ \ \ \ set\ power\ 0\n\ \ \ \ \ \ \ \ set\ compare\ \[math::bigfloat::compare\ \$y\ \$kb\]\n\ \ \ \ \ \ \ \ while\ \{\$compare>=0\ \}\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ incr\ power\n\ \ \ \ \ \ \ \ \ \ \ \ set\ y\ \[math::bigfloat::div\ \$y\ \$kb\]\n\ \ \ \ \ \ \ \ \ \ \ \ set\ compare\ \[math::bigfloat::compare\ \$y\ \$kb\]\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ set\ y\ \[math::bigfloat::todouble\ \$y\]\n\ \ \ \ \ \ \ \ return\ \[list\ \$y\ \$power\]\n\ \ \ \ \}\n\ \ \ \ #\n\ \ \ \ #\ compare\ --\n\ \ \ \ #\ \ \ Compare\ two\ files\ sizes\ represented\ in\ human\ readable\ form,\ and\n\ \ \ \ #\ \ \ return\ -1\ if\ size1\ in\ less\ than\ size2,\ 0\ if\ size1\ and\n\ \ \ \ #\ \ \ size2\ are\ equal\ or\ 1\ if\ size2\ is\ greater\ than\ size2.\n\ \ \ \ #\ \ \ The\ two\ file\ sizes\ may\ be\ in\ different\ units\ but\ in\ the\ same\n\ \ \ \ #\ \ \ unit\ system,\ that\ is,\ the\ two\ values\ in\ decimal\ units,\ or\ the\ two\n\ \ \ \ #\ \ \ values\ in\ binary\ units.\n\ \ \ \ #\ Arguments:\n\ \ \ \ #\ \ \ size1,\ size2:\ the\ size\ of\ the\ first\ file/directory\ which\ is\ a\ list\ of\ two\ items\n\ \ \ \ #\ \ \ \ \ as\ returned\ by\ \"bytestohr\"\ :\n\ \ \ \ #\ \ \ \ \ -\ the\ first\ item\ is\ a\ real\ value\ representing\ the\ size,\n\ \ \ \ #\ \ \ \ \ -\ the\ second\ item\ is\ the\ unit.\n\ \ \ \ #\ \ \ -unit\ value\ :\ the\ unit\ system\ to\ convert\ from\ bytes.\n\ \ \ \ #\ \ \ \ \ \ If\ \"value\"\ is\ \"binary\"\ then\ one\ kilobyte\ is\ made\ of\ 1024\ bytes.\n\ \ \ \ #\ \ \ \ \ \ If\ \"value\"\ is\ \"decimal\"\ then\ one\ kilobyte\ is\ made\ of\ 1000\ bytes.\n\ \ \ \ #\ \ \ \ \ \ The\ default\ unit\ system\ is\ decimal.\n\ \ \ \ #\ \ \ -integerpackage\ value\ :\ the\ package\ to\ process\ integer\ values\n\ \ \ \ #\ \ \ \ \ \ If\ \"value\"\ is\ \"Tcl\"\ then\ the\ integers\ are\ processed\ with\ Tcl\ \"expr\"\ command\n\ \ \ \ #\ \ \ \ \ \ If\ \"value\"\ is\ \"bigfloat\"\ then\ the\ integers\ are\ processed\ with\ Tcl\ lib\ package\ \"bigfloat\"\n\ \ \ \ #\n\ \ \ \ proc\ hrfilesize::compare\ \{size1\ size2\ args\}\ \{\n\ \ \ \ \ \ \ \ #\n\ \ \ \ \ \ \ \ #\ Process\ options\n\ \ \ \ \ \ \ \ #\n\ \ \ \ \ \ \ \ foreach\ \{key\ value\}\ \$args\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ hrfilesize::configure\ \$key\ \$value\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ #\n\ \ \ \ \ \ \ \ #\ Get\ values\ and\ units\n\ \ \ \ \ \ \ \ #\n\ \ \ \ \ \ \ \ set\ size1value\ \[lindex\ \$size1\ 0\]\n\ \ \ \ \ \ \ \ set\ size1unit\ \[lindex\ \$size1\ 1\]\n\ \ \ \ \ \ \ \ set\ size2value\ \[lindex\ \$size2\ 0\]\n\ \ \ \ \ \ \ \ set\ size2unit\ \[lindex\ \$size2\ 1\]\n\ \ \ \ \ \ \ \ #\n\ \ \ \ \ \ \ \ #\ The\ two\ values\ are\ in\ the\ same\ unit\ :\n\ \ \ \ \ \ \ \ #\ compare\ the\ values.\n\ \ \ \ \ \ \ \ #\n\ \ \ \ \ \ \ \ if\ \{\$size1unit==\$size2unit\}\ then\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ if\ \{\$size1value\ <\ \$size2value\}\ then\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ set\ compare\ -1\n\ \ \ \ \ \ \ \ \ \ \ \ \}\ elseif\ \{\$size1value\ ==\ \$size2value\}\ then\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ set\ compare\ 0\n\ \ \ \ \ \ \ \ \ \ \ \ \}\ else\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ set\ compare\ 1\n\ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \}\ else\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ #\n\ \ \ \ \ \ \ \ \ \ \ \ #\ Compare\ the\ units\n\ \ \ \ \ \ \ \ \ \ \ \ #\n\ \ \ \ \ \ \ \ \ \ \ \ set\ unit1index\ \[lsearch\ \$hrfilesize::powertounitmap\ \$size1unit\]\n\ \ \ \ \ \ \ \ \ \ \ \ set\ unit2index\ \[lsearch\ \$hrfilesize::powertounitmap\ \$size2unit\]\n\ \ \ \ \ \ \ \ \ \ \ \ if\ \{\$unit1index==-1\ ||\ \$unit2index==-1\}\ then\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ error\ \"The\ current\ unit\ system\ \$hrfilesize::unitsystem\ does\ not\ match\ the\ given\ units\ for\ \$size1\ and\ \$size2.\"\n\ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \ \ \ \ if\ \{\$unit1index\ <\ \$unit2index\}\ then\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ set\ compare\ -1\n\ \ \ \ \ \ \ \ \ \ \ \ \}\ else\ \{\n\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ set\ compare\ 1\n\ \ \ \ \ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ \}\n\ \ \ \ \ \ \ \ return\ \$compare\n\ \ \ \ \}\n\ \ \ \ #\n\ \ \ \ #\ Automatic\ configuration\ of\ the\ package\ at\ loading.\n\ \ \ \ #\n\ \ \ \ hrfilesize::configure\ -unit\ \"decimal\"\n\ \ \ \ hrfilesize::configure\ -realformat\ \"%.1f\"\n\ \ \ \ hrfilesize::configure\ -integerpackage\ \"bigfloat\"\n======\n\nAnd\ here\ are\ the\ tests.\n======\n\ \ \ \ package\ require\ tcltest\n\ \ \ \ namespace\ import\ tcltest::test\n\ \ \ \ lappend\ ::auto_path\ .\n\ \ \ \ package\ require\ hrfilesize\ 1.0\n\n\ \ \ \ #\n\ \ \ \ #\ Caution\ !\n\ \ \ \ #\ \ \ Use\ constant\ string\ values\ instead\ of\ using\ Tcl\ expr\ in\ integer\n\ \ \ \ #\ \ \ values\ only.\n\ \ \ \ #\ \ \ This\ is\ because\ Tcl\ string\ to\ integer\ conversion\ is\ based\ on\n\ \ \ \ #\ \ \ the\ C\ integer\ long\ type,\ so\ that\ the\ maximum\ integer\ is\ approximately\n\ \ \ \ #\ \ \ 2\ GB.\n\ \ \ \ #\n\ \ \ \ tcltest::test\ hrfilesize-binary-1\ \{50\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ 50\ -unit\ binary\]\n\ \ \ \ \}\ \{50.0\ B\}\n\ \ \ \ tcltest::test\ hrfilesize-binary-2\ \{10\ 000\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ 10000\ -unit\ binary\]\n\ \ \ \ \}\ \{9.8\ KiB\}\n\ \ \ \ tcltest::test\ hrfilesize-binary-3\ \{10\ 000\ 000\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ 10000000\ -unit\ binary\]\n\ \ \ \ \}\ \{9.5\ MiB\}\n\ \ \ \ tcltest::test\ hrfilesize-binary-4\ \{10\ 000\ 000\ 000\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ 10000000000\ -unit\ binary\]\n\ \ \ \ \}\ \{9.3\ GiB\}\n\ \ \ \ tcltest::test\ hrfilesize-binary-5\ \{10\ 000\ 000\ 000\ 000\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ 10000000000000\ -unit\ binary\]\n\ \ \ \ \}\ \{9.1\ TiB\}\n\ \ \ \ tcltest::test\ hrfilesize-binary-6\ \{Pib\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ 10000000000000000\ -unit\ binary\]\n\ \ \ \ \}\ \{8.9\ PiB\}\n\ \ \ \ tcltest::test\ hrfilesize-binary-7\ \{Eib\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ 10000000000000000000\ -unit\ binary\]\n\ \ \ \ \}\ \{8.7\ EiB\}\n\ \ \ \ tcltest::test\ hrfilesize-binary-8\ \{1024\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ 1024\ -unit\ binary\]\n\ \ \ \ \}\ \{1.0\ KiB\}\n\ \ \ \ tcltest::test\ hrfilesize-binary-9\ \{1025\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ 1025\ -unit\ binary\]\n\ \ \ \ \}\ \{1.0\ KiB\}\n\ \ \ \ tcltest::test\ hrfilesize-binary-10\ \{0\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ 0\ -unit\ binary\]\n\ \ \ \ \}\ \{0.0\ B\}\n\ \ \ \ tcltest::test\ hrfilesize-binary-11\ \{1\ Mbyte\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ \[expr\ \{1024*1024\}\]\ -unit\ binary\]\n\ \ \ \ \}\ \{1.0\ MiB\}\n\n\ \ \ \ tcltest::test\ hrfilesize-decimal-1\ \{50\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ 50\ -unit\ decimal\]\n\ \ \ \ \}\ \{50.0\ B\}\n\ \ \ \ tcltest::test\ hrfilesize-decimal-2\ \{10000\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ 10000\ -unit\ decimal\]\n\ \ \ \ \}\ \{10.0\ KB\}\n\ \ \ \ tcltest::test\ hrfilesize-decimal-3\ \{10000000\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ 10000000\ -unit\ decimal\]\n\ \ \ \ \}\ \{10.0\ MB\}\n\ \ \ \ tcltest::test\ hrfilesize-decimal-4\ \{10000000000\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ 10000000000\ -unit\ decimal\]\n\ \ \ \ \}\ \{10.0\ GB\}\n\ \ \ \ tcltest::test\ hrfilesize-decimal-5\ \{10000000000000\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ 10000000000000\ -unit\ decimal\]\n\ \ \ \ \}\ \{10.0\ TB\}\n\ \ \ \ tcltest::test\ hrfilesize-decimal-6\ \{Pib\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ 10000000000000000\ -unit\ decimal\]\n\ \ \ \ \}\ \{10.0\ PB\}\n\ \ \ \ tcltest::test\ hrfilesize-decimal-7\ \{Eib\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ 10000000000000000000\ -unit\ decimal\]\n\ \ \ \ \}\ \{10.0\ EB\}\n\ \ \ \ tcltest::test\ hrfilesize-decimal-8\ \{1024\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ 1024\ -unit\ decimal\]\n\ \ \ \ \}\ \{1.0\ KB\}\n\ \ \ \ tcltest::test\ hrfilesize-decimal-9\ \{1025\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ 1025\ -unit\ decimal\]\n\ \ \ \ \}\ \{1.0\ KB\}\n\ \ \ \ tcltest::test\ hrfilesize-decimal-10\ \{0\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ 0\ -unit\ decimal\]\n\ \ \ \ \}\ \{0.0\ B\}\n\ \ \ \ tcltest::test\ hrfilesize-decimal-11\ \{1\ Mbyte\ bytes\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::bytestohr\ \[expr\ \{1024*1024\}\]\ -unit\ decimal\]\n\ \ \ \ \}\ \{1.1\ MB\}\n\n\ \ \ \ tcltest::test\ hrfilesize-error-1\ \{what\ happens\ if\ we\ give\ a\ real\ value\ ?\}\ \{\n\ \ \ \ \ \ \ \ set\ errflag\ \[catch\ \{hrfilesize::bytestohr\ 50.\}\ errmsg\]\n\ \ \ \ \ \ \ \ set\ result\ \[list\ \$errflag\ \$errmsg\]\n\ \ \ \ \}\ \{1\ \{first\ argument\ is\ not\ an\ integer\}\}\n\ \ \ \ tcltest::test\ hrfilesize-error-2\ \{what\ happens\ if\ we\ give\ a\ size\ larger\ than\ the\ larger\ unit\ ?\}\ \{\n\ \ \ \ \ \ \ \ set\ errflag\ \[catch\ \{hrfilesize::bytestohr\ 10000000000000000000000\ -unit\ decimal\}\ errmsg\]\n\ \ \ \ \ \ \ \ set\ result\ \[list\ \$errflag\ \$errmsg\]\n\ \ \ \ \}\ \{1\ \{File\ size\ larger\ than\ the\ maximum\ available\ size\ unit\ (power\ :\ 7)\}\}\n\ \ \ \ tcltest::test\ hrfilesize-compare-1\ \{two\ sizes\ in\ B\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::compare\ \"1.0\ B\"\ \"2.0\ B\"\]\n\ \ \ \ \}\ \{-1\}\n\ \ \ \ tcltest::test\ hrfilesize-compare-2\ \{two\ sizes\ in\ B\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::compare\ \"1.0\ B\"\ \"1.0\ B\"\]\n\ \ \ \ \}\ \{0\}\n\ \ \ \ tcltest::test\ hrfilesize-compare-3\ \{two\ sizes\ in\ B\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::compare\ \"2.0\ B\"\ \"1.0\ B\"\]\n\ \ \ \ \}\ \{1\}\n\ \ \ \ tcltest::test\ hrfilesize-compare-4\ \{size1\ in\ B,\ size2\ in\ KB\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::compare\ \"1.0\ B\"\ \"1.0\ KB\"\]\n\ \ \ \ \}\ \{-1\}\n\ \ \ \ tcltest::test\ hrfilesize-compare-5\ \{size1\ in\ B,\ size2\ in\ KB\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::compare\ \"1.0\ KB\"\ \"1.0\ B\"\]\n\ \ \ \ \}\ \{1\}\n\ \ \ \ tcltest::test\ hrfilesize-compare-6\ \{size1\ in\ KB,\ size2\ in\ MB\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::compare\ \"1.0\ KB\"\ \"1.0\ MB\"\]\n\ \ \ \ \}\ \{-1\}\n\ \ \ \ tcltest::test\ hrfilesize-compare-7\ \{size1\ in\ KB,\ size2\ in\ KiB\}\ \{\n\ \ \ \ \ \ \ \ set\ errflag\ \[catch\ \{hrfilesize::compare\ \"1.0\ KB\"\ \"1.0\ KiB\"\}\ errmsg\]\n\ \ \ \ \ \ \ \ set\ res\ \[list\ \$errflag\ \$errmsg\]\n\ \ \ \ \}\ \{1\ \{The\ current\ unit\ system\ decimal\ does\ not\ match\ the\ given\ units\ for\ 1.0\ KB\ and\ 1.0\ KiB.\}\}\n\ \ \ \ tcltest::test\ hrfilesize-compare-8\ \{size1\ in\ KiB,\ size2\ in\ MiB\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::compare\ \"1.0\ KiB\"\ \"1.0\ MiB\"\ -unit\ binary\]\n\ \ \ \ \}\ \{-1\}\n\ \ \ \ tcltest::test\ hrfilesize-compare-8\ \{size1\ in\ KiB,\ size2\ in\ MiB\}\ \{\n\ \ \ \ \ \ \ \ set\ res\ \[hrfilesize::compare\ \"1.0\ MiB\"\ \"1.0\ KiB\"\ -unit\ binary\]\n\ \ \ \ \}\ \{1\}\n\n\ \ \ \ ::tcltest::cleanupTests\n======\n\n----\n<<discussion>>\n**See\ also**\n\ \ \ *\ \[file\]\n\ \ \ *\ \[file\ exists\]\n\ \ \ *\ \[file\ stat\]\n\ \ \ *\ \[directory\ size\]\n\ \ \ *\ \[Narrow\ formatting\]\n\ \ \ *\ \[hrbytesize\]\n<<categories>>\ Tcl\ syntax\ help\ |\ Command\ |\ Introspection\ |\ File} CALL {my revision {file size}} CALL {::oo::Obj1031926 process revision/file+size} CALL {::oo::Obj1031924 process}

-errorcode

NONE

-errorinfo

Unknow state transition: LINE -> END
    while executing
"error $msg"
    (class "::Wiki" method "render_wikit" line 6)
    invoked from within
"my render_$default_markup $N $C $mkup_rendering_engine"
    (class "::Wiki" method "render" line 8)
    invoked from within
"my render $name $C"
    (class "::Wiki" method "revision" line 31)
    invoked from within
"my revision $page"
    (class "::Wiki" method "process" line 56)
    invoked from within
"$server process [string trim $uri /]"

-errorline

4