John Beckett wrote:
> A.J.Mechelynck wrote:
>
>> What about a different function to return, say, the number of
>> 1K blocks (or the number of times 2^n bytes, with a parameter
>> passed to the function) that a file uses?
>
>
> Yes, that's a much more general and better idea.
>
> Since there's probably not much need for this, I think that
> simplicity would be good. That is, have the function work in a
> fixed way with no options.
>
> Re Dr.Chip's LargeFile script: It occurs to me that another
> workaround would be to use system() to capture the output of
> 'ls -l file' or 'dir file' (need an option for which).
>
> Then do some funky editing to calculate the number of digits in
> the file length. If more than 9, treat file as large.
>
> I'm playing with a tiny utility to help the LargeFile script.
> Bluesky: Its code (64-bit file size) could potentially be
> incorporated in Vim. I'll post results in vim-dev.
(I've moved this over to vim-dev)
I've attached a patch to vim 7.1 which extends getfsize(); with the
patch, getfsize() takes an optional
second parameter which gives one the ability to specify a "unitsize".
In other words,
getfsize("eval.c") -> 478347 (after the patch)
getfsize("eval.c",1000) -> 479 (truncated upwards)
I'll be awaiting Bram's input before making use of this in LargeFile.vim !
Regards,
Chip Campbell
*** src/o_eval.c 2007-05-25 08:52:12.000000000 -0400
--- src/eval.c 2007-05-25 09:04:43.000000000 -0400
***************
*** 7094,7100 ****
{"getcwd", 0, 0, f_getcwd},
{"getfontname", 0, 1, f_getfontname},
{"getfperm", 1, 1, f_getfperm},
! {"getfsize", 1, 1, f_getfsize},
{"getftime", 1, 1, f_getftime},
{"getftype", 1, 1, f_getftype},
{"getline", 1, 2, f_getline},
--- 7094,7100 ----
{"getcwd", 0, 0, f_getcwd},
{"getfontname", 0, 1, f_getfontname},
{"getfperm", 1, 1, f_getfperm},
! {"getfsize", 1, 2, f_getfsize},
{"getftime", 1, 1, f_getftime},
{"getftype", 1, 1, f_getftype},
{"getline", 1, 2, f_getline},
***************
*** 10135,10142 ****
{
if (mch_isdir(fname))
rettv->vval.v_number = 0;
! else
rettv->vval.v_number = (varnumber_T)st.st_size;
}
else
rettv->vval.v_number = -1;
--- 10135,10151 ----
{
if (mch_isdir(fname))
rettv->vval.v_number = 0;
! else if (argvars[1].v_type == VAR_UNKNOWN)
rettv->vval.v_number = (varnumber_T)st.st_size;
+ else
+ {
+ unsigned long unitsize;
+ unsigned long stsize;
+ unitsize= get_tv_number(&argvars[1]);
+ stsize= st.st_size/unitsize;
+ if(stsize*unitsize < st.st_size) ++stsize;
+ rettv->vval.v_number = (varnumber_T) stsize;
+ }
}
else
rettv->vval.v_number = -1;
*** runtime/doc/o_eval.txt 2007-05-25 09:00:08.000000000 -0400
--- runtime/doc/eval.txt 2007-05-25 09:06:19.000000000 -0400
***************
*** 1615,1621 ****
getcmdtype() String return the current command-line type
getcwd() String the current working directory
getfperm( {fname}) String file permissions of file {fname}
! getfsize( {fname}) Number size in bytes of file {fname}
getfontname( [{name}]) String name of font being used
getftime( {fname}) Number last modification time of file
getftype( {fname}) String description of type of file {fname}
--- 1615,1621 ----
getcmdtype() String return the current command-line type
getcwd() String the current working directory
getfperm( {fname}) String file permissions of file {fname}
! getfsize( {fname} [,unitsize]) Number size in bytes of file {fname}
getfontname( [{name}]) String name of font being used
getftime( {fname}) Number last modification time of file
getftype( {fname}) String description of type of file {fname}
***************
*** 2819,2827 ****
getcwd() The result is a String, which is the name of the current
working directory.
! getfsize({fname}) *getfsize()*
The result is a Number, which is the size in bytes of the
given file {fname}.
If {fname} is a directory, 0 is returned.
If the file {fname} can't be found, -1 is returned.
--- 2819,2829 ----
getcwd() The result is a String, which is the name of the current
working directory.
! getfsize({fname} [,unitsize]) *getfsize()*
The result is a Number, which is the size in bytes of the
given file {fname}.
+ If unitsize is given, then the file {fname}'s size will be
+ returned in units of size unitsize bytes (truncated up).
If {fname} is a directory, 0 is returned.
If the file {fname} can't be found, -1 is returned.