summaryrefslogtreecommitdiff
path: root/usr.bin/sort/sort.h
AgeCommit message (Collapse)Author
2016-06-01Add the posix -C option (-c but quieter). Fix -R to work properly whenkre
setting \n as the record delimited using a numeric value rather than literal \n - and to not incorrectly turn \n into a field separator if -R is used to make some other char the record separator (\n becomes a field separator in that case as long as the field separator remains "white space" but should not be in any other case - unless set explicitly of course.) Plus more cosmetic changes - the man page and usage are updated to make it more clear that the 2 (or 1) params to -k are not fields (field1 and field2) but specifiers of the beginning and end of one key field. There was an unused 'x' option in the GETOPTS string. The usage message is reformatted to display properly on both 80 col and > 80 col displays (on < 80 it will still probably look pretty ugly ... perhaps not quite so bad though), and is also updated to show the different usage for the -c case (and -C) from the others (only 1 file permitted) - the man page synopsis has a similar update. Using more than one of -c -C or -m generates a usage message rather than just ignoring the -m as it did before (there was no -C before of course). Aside from the bug fix to the interaction between -R and -t, there are no changes that affect the way anything is sorted (or read, or written). Discussed on tech-userlevel earlier this week.
2015-08-05add a description about what was being attempted to failed writes messages.mrg
2011-09-16Use __deadjoerg
2010-12-18Add an 'l' style for sorting that sorts by the string length of the field.christos
2010-06-05fixit() needs to know the getopt options list to do its thing correctly.dholland
2010-02-05Don't touch past the end of allocated region. It results segmentationenami
violation.
2009-09-28Fix borked fix for sort relying on realloc() changing the buffer end.dsl
Sorts of more than 8MB data now probably work again.
2009-09-26Move all the fopen() calls out of the record read routines into the callers.dsl
Split the merge sort so that fsort() can pass the 'FILE *' of the temporary files to be merged into the merge code. Don't rely on realloc() not moving the end address of a buffer! Rework merge sort so that it sorts pointers to 'struct mfile' and only copies about sort record descriptors. No functional change intended.
2009-09-10Save length of key instead of relying of the weight of the record sep.dsl
This frees a byte value to use for 'end of key' (to correctly sort short keys) while still having a weight assigned to the field sep. (Unless -t is given, the field sep is in the field data.) Do reverse sorts by writing the output file in reverse order (rather than reversing the sort - apart from merges). All key compares are now unweighted. For 'sort -u' mark duplicates keys during the sort and don't write to the output. Use -S to mean a posix sort - where equal keys are sorted using the raw record (rather than being kept in the original order). For 'sort -f' (no keys) generate a key of the folded data (as for -n -i and -d), simplifies the code and allows a 'posix' sort.
2009-09-05Now we have our own radix_sort() change the interface so that we passdsl
an array of 'RECHEADER *' and remove all the crappy stuff that backed up by REC_DATA_OFFSET (etc). Also change radix_sort() to return the number of elements, soon to be used to drop duplicate keys (for sort -u).
2009-09-05Include a local copy of the sradixsort() code from libc.dsl
Currently unchanged apart from the deletion of the 'unstable' version and other unneeded code. Use fldtab[0]. not fldtab-> when we are referring to the global info in the 0th entry to emphasise that this entry is different. fldtab[0].weights is only needed in the SINGL_FLD case - so set it there. Re-indent a big 'if' is setfield() so that the line breaks match the logic - which looks dubious now!
2009-08-22Rework the way sort generates sort keys:dsl
- If we generate a key, it is always sortable using memcmp() - If we are sorting the whole record, then a weight-table must be used during compares. - Major surgery to encoding of numbers to ensure unique keys for equal numeric values. Reverse numerics are handled by inverting the sign. - Case folding (-f) is handled when the sort keys are generated. No other code has to care at all. - Key uniqueness (-u) is done during merge for large datasets. It only has to be done when writing the output file for small files. Since the file is in key order this is simple! Probably fixes all of: PR/27257 PR/25551 PR/22182 PR/31095 PR/30504 PR/36816 PR/37860 PR/39308 Also PR/18614 should no longer die, but a little more work needs to be done on the merging for very large files.
2009-08-20Delete more unwanted/unused cruft.dsl
Simplify logic for reading input records. Do a merge sort whenever we have 16 partial sorted blocks. The patient is breathing, but still carrying a lot of extra weight.
2009-08-18The code that attempted to sort large files by sorting each chunk by thedsl
first key byte and writing to a temp file, then sorting the records from each temp file that had the same first key byte (and repeating for upto 4 key bytes) was a nice idea, but completely doomed to failure. Eg PR/9308 where a 70MB file has all but one record the same and short keys. Not only does the code not work, it is rather guaranteed to be slow. Instead always use a merge sort for fully sorted chunk of records (each temporary file contains one lot of sorted records). The -H option already did this, so just rip out all the code and variables that can't be used when -H was specified. Further cleanup to come ...
2009-08-16Replace all uses of sizeof(TRECHEADER) with REC_DATA_OFFSET - whichdsl
is defined as offsetof(RECHEADER, data). Delete TRECHEADER.
2009-08-15Remove reference to db.h by using separate ptr+len fields for the onlydsl
structure that used it. Pass end of keybuf area, not size to enterkey() - largely to remove a variable who'se use isn't obvious from the name! The structute of this code sucks.
2009-04-13Fix WARNS=4 issues (-Wcast-qual -Wsign-compare)lukem
2008-04-28Remove clause 3 and 4 from TNF licensesmartin
2004-02-15remove compile-time limit on number of -k options, allocate necessaryjdolecek
structures as-needed
2003-08-07add TNF copyrightjdolecek
2003-08-07Move UCB-licensed code from 4-clause to 3-clause licence.agc
Patches provided by Joel Baker in PR 22365, verified by myself.
2002-12-25make function merge() static in msort.cjdolecek
cosmetic change to how local variable is incremented (moved to for(;;))
2002-12-24put contents of extern.h directly to sort.h, and g/c extern.hjdolecek
de-__P()
2002-12-24add extern definition for ncols and clist[] to sort.h, eliminate extrajdolecek
definitions in init.c and field.c g/c MAXMERGE
2001-02-19cosmetic changes - make keylist[] static and remove extern definitionjdolecek
in fsort.h, move macro SALIGN() from sort.h to fsort.c
2001-01-19adjust intendationjdolecek
2001-01-16- fix alignment problem.shin
2001-01-12alltable[], itable[], dtable[] were moved to init.c, g/c from sort.[ch]jdolecek
put extern declaration for gweights[] to sort.h
2001-01-11general cleanup of file list passing:jdolecek
* get rid of union f_handle, replace by passing explicit int parameter and (new) struct filelist * add new typedefs gen_func_t and put_func_t and use where appropriate
2001-01-08constify a bit, small cleanupsjdolecek
2001-01-08by default, use stable sortjdolecek
add -S flag to switch to non-stable sort; for GNU sort compatibility, provide -s flag too
2000-10-16enlarge line buffer as necessary, so that it's possiblejdolecek
to process lines longer than 65522 characters constify, rename MAXLLEN to DEFLLEN
2000-10-07Include <string.h> to get prototype for memcpy(). Fixed compile problemssimonb
on alpha (and other LP64 archs?). XXX: Can't gcc be fixed so that it doesn't auto-prototype mem*()??
2000-10-07Two classes of changes from the initial OpenBSD commit of this sort(1):bjh21
FILE * variables are called "fp" rather than "fd". Better (safer) temporary-file handling.
2000-10-07Hit sort(1) with a hammer till it compiles.bjh21
Also add RCSIDs.
2000-10-074.4BSD-Lite2 contrib/sortbjh21