sbase

suckless unix tools
git clone git://git.2f30.org/sbase.git
Log | Files | Refs | README | LICENSE

commit bd9a81951f4e55c247d29312b893be96c05b08ae
parent f7403ce6c6a9adb3c8567c7ab103c9e2c1e94f9a
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Tue Apr  1 15:30:17 +0200

split: dont use table lookup for size

Signed-off-by: Hiltjo Posthuma <hiltjo@codemadness.org>

Diffstat:
split.c | 19++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/split.c b/split.c @@ -22,15 +22,10 @@ main(int argc, char **argv) char *prefix = "x"; char *file = NULL; char *tmp, *end; - uint64_t sizes['M'+1]; uint64_t size = 1000, scale, n; int always = 0; FILE *in=stdin, *out=NULL; - sizes['K'] = 1024; - sizes['M'] = 1024L*1024L; - sizes['G'] = 1024L*1024L*1024L; - ARGBEGIN { case 'b': always = 1; @@ -41,9 +36,19 @@ main(int argc, char **argv) size = strtoull(tmp, &end, 10); if(*end == '\0') break; - if(strchr("KMG", toupper(*end)) == NULL || end[1] != '\0') + switch(toupper(*end)) { + case 'K': + scale = 1024; + break; + case 'M': + scale = 1024L * 1024L; + break; + case 'G': + scale = 1024L * 1024L * 1024L; + break; + default: usage(); - scale = sizes[toupper(*end)]; + } if(size > (UINT64_MAX/scale)) eprintf("'%s': out of range\n", tmp); size *= scale;