From owner-p4-projects@FreeBSD.ORG Thu May 1 22:47:54 2008 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 526121065675; Thu, 1 May 2008 22:47:54 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 12ED01065672 for ; Thu, 1 May 2008 22:47:54 +0000 (UTC) (envelope-from gabor@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id F286B8FC17 for ; Thu, 1 May 2008 22:47:53 +0000 (UTC) (envelope-from gabor@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id m41MlrDh063351 for ; Thu, 1 May 2008 22:47:53 GMT (envelope-from gabor@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id m41MlrUp063349 for perforce@freebsd.org; Thu, 1 May 2008 22:47:53 GMT (envelope-from gabor@freebsd.org) Date: Thu, 1 May 2008 22:47:53 GMT Message-Id: <200805012247.m41MlrUp063349@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to gabor@freebsd.org using -f From: Gabor Kovesdan To: Perforce Change Reviews Cc: Subject: PERFORCE change 141017 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 May 2008 22:47:54 -0000 http://perforce.freebsd.org/chv.cgi?CH=141017 Change 141017 by gabor@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); }