PERFORCE change 141017 for review
Gabor Kovesdan
gabor at FreeBSD.org
Thu May 1 22:47:54 UTC 2008
http://perforce.freebsd.org/chv.cgi?CH=141017
Change 141017 by gabor at gabor_server on 2008/05/01 22:47:19
- Implement -S / --buffer-size
Affected files ...
.. //depot/projects/soc2008/gabor_textproc/sort/extern.h#3 edit
.. //depot/projects/soc2008/gabor_textproc/sort/fsort.c#3 edit
.. //depot/projects/soc2008/gabor_textproc/sort/sort.c#5 edit
Differences ...
==== //depot/projects/soc2008/gabor_textproc/sort/extern.h#3 (text+ko) ====
@@ -44,7 +44,7 @@
void fmerge(int, union f_handle, int,
int (*)(int, union f_handle, int, RECHEADER *, u_char *, struct field *),
FILE *, void (*)(RECHEADER *, FILE *), struct field *);
-void fsort(int, int, union f_handle, int, FILE *, struct field *);
+void fsort(int, int, union f_handle, int, FILE *, struct field *, size_t);
FILE *ftmp(void);
int geteasy(int, union f_handle,
int, RECHEADER *, u_char *, struct field *);
==== //depot/projects/soc2008/gabor_textproc/sort/fsort.c#3 (text+ko) ====
@@ -66,14 +66,13 @@
void
fsort(int binno, int depth, union f_handle infiles, int nfiles, FILE *outfp,
- struct field *ftbl)
+ struct field *ftbl, size_t bufsize)
{
int (*get)(int, union f_handle, int, RECHEADER *,
u_char *, struct field *);
u_char *weights, **keypos, *bufend, *tmpbuf;
static u_char *buffer, **keylist;
- static size_t bufsize;
int ntfiles, mfct = 0, total, i, maxb, lastb, panic = 0;
int c, nelem;
long sizes[NBINS+1];
@@ -92,7 +91,6 @@
tfield[0].icol.num = 1;
weights = ftbl[0].weights;
if (buffer == NULL) {
- bufsize = BUFSIZE;
if ((buffer = malloc(bufsize)) == NULL ||
(keylist = calloc(MAXNUM, sizeof(u_char *))) == NULL)
err(2, NULL);
@@ -210,7 +208,7 @@
lastb = i;
total += sizes[i];
}
- if (sizes[maxb] < max((total / 2) , BUFSIZE))
+ if (sizes[maxb] < max((total / 2) , bufsize))
maxb = lastb; /* otherwise pop after last bin */
fstack[tfiles.top].lastb = lastb;
fstack[tfiles.top].maxb = maxb;
@@ -221,7 +219,8 @@
if (!sizes[i]) /* bin empty; step ahead file offset */
get(i, tfiles, ntfiles, crec, bufend, 0);
else
- fsort(i, depth+1, tfiles, ntfiles, outfp, ftbl);
+ fsort(i, depth+1, tfiles, ntfiles, outfp,
+ ftbl, bufsize);
}
if (lastb != maxb) {
if (prevfp != outfp)
@@ -232,7 +231,7 @@
get(i, tfiles, ntfiles, crec, bufend,0);
else
fsort(i, depth+1, tfiles, ntfiles,
- prevfp, ftbl);
+ prevfp, ftbl, bufsize);
}
/* sort biggest (or last) bin at this level */
==== //depot/projects/soc2008/gabor_textproc/sort/sort.c#5 (text+ko) ====
@@ -118,8 +118,7 @@
{ "numric-sort", no_argument, NULL, 'n' },
{ "reverse", no_argument, NULL, 'r' },
{ "output", required_argument, NULL, 'o' },
-/* XXX: UNIMPLEMENTED
- { "buffer-size", required_argument, NULL, 'S' }, */
+ { "buffer-size", required_argument, NULL, 'S' },
{ "stable", no_argument, NULL, 's' },
{ "temporary-directory", required_argument, NULL, 'T' },
{ "field-separator", required_argument, NULL, 't' },
@@ -142,6 +141,7 @@
union f_handle filelist;
FILE *outfp = NULL;
void *p;
+ size_t bufsize = BUFSIZE;
setlocale(LC_ALL, "");
@@ -154,7 +154,7 @@
fixit(&argc, argv);
if (!issetugid() && (outfile = getenv("TMPDIR")))
tmpdir = outfile;
- while ((ch = getopt_long(argc, argv, "bcdfik:mHno:rR:st:T:uvy:z", longopts, NULL)) != -1) {
+ while ((ch = getopt_long(argc, argv, "bcdfik:mHno:rR:S:st:T:uvy:z", longopts, NULL)) != -1) {
switch (ch) {
case 'b': fldtab->flags |= BI | BT;
break;
@@ -195,6 +195,11 @@
d_mask['\n'] = d_mask[' '];
d_mask[REC_D] = REC_D_F;
break;
+ case 'S':
+ bufsize = (size_t) strtol(optarg, (char **)NULL, 10);
+ if (bufsize <= 0)
+ usage("invalid buffer size");
+ break;
case 's':
STABLE = 1;
break;
@@ -338,7 +343,7 @@
if (mflag)
fmerge(-1, filelist, argc-optind, get, outfp, putline, fldtab);
else
- fsort(-1, 0, filelist, argc-optind, outfp, fldtab);
+ fsort(-1, 0, filelist, argc-optind, outfp, fldtab, bufsize);
if (outfile != outpath) {
if (access(outfile, 0))
err(2, "%s", outfile);
@@ -377,6 +382,6 @@
warnx("%s", msg);
(void)fprintf(stderr, "usage: %s [-bcdfHimnrsuz] "
"[-k field1[,field2]] [-o output] [-R char]\n"
- "\t[-T dir] [-t char] [file ...]\n", __progname);
+ "\t[-S size] [-T dir] [-t char] [file ...]\n", __progname);
exit(2);
}
More information about the p4-projects
mailing list