[BACK]Return to sort.h CVS log [TXT][DIR] Up to [local] / src / usr.bin / sort

Annotation of src/usr.bin/sort/sort.h, Revision 1.8

1.8     ! deraadt     1: /*     $OpenBSD: sort.h,v 1.7 2007/08/21 20:29:25 millert Exp $        */
1.1       millert     2:
                      3: /*-
                      4:  * Copyright (c) 1993
                      5:  *     The Regents of the University of California.  All rights reserved.
                      6:  *
                      7:  * This code is derived from software contributed to Berkeley by
                      8:  * Peter McIlroy.
                      9:  *
                     10:  * Redistribution and use in source and binary forms, with or without
                     11:  * modification, are permitted provided that the following conditions
                     12:  * are met:
                     13:  * 1. Redistributions of source code must retain the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer.
                     15:  * 2. Redistributions in binary form must reproduce the above copyright
                     16:  *    notice, this list of conditions and the following disclaimer in the
                     17:  *    documentation and/or other materials provided with the distribution.
1.6       millert    18:  * 3. Neither the name of the University nor the names of its contributors
1.1       millert    19:  *    may be used to endorse or promote products derived from this software
                     20:  *    without specific prior written permission.
                     21:  *
                     22:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     23:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     24:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     25:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     26:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     27:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     28:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     29:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     30:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     31:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     32:  * SUCH DAMAGE.
                     33:  *
                     34:  *     @(#)sort.h      8.1 (Berkeley) 6/6/93
                     35:  */
                     36:
                     37: #include <db.h>
                     38: #include <err.h>
                     39: #include <errno.h>
                     40: #include <fcntl.h>
                     41: #include <limits.h>
                     42: #include <stdio.h>
                     43: #include <stdlib.h>
1.2       dgregor    44: #include <string.h>
1.1       millert    45:
                     46: #define NBINS 256
                     47: #define MAXMERGE 16
                     48:
                     49: /* values for masks, weights, and other flags. */
                     50: #define I 1            /* mask out non-printable characters */
                     51: #define D 2            /* sort alphanumeric characters only */
                     52: #define N 4            /* Field is a number */
                     53: #define F 8            /* weight lower and upper case the same */
                     54: #define R 16           /* Field is reversed with respect to the global weight */
                     55: #define BI 32          /* ignore blanks in icol */
                     56: #define BT 64          /* ignore blanks in tcol */
                     57:
                     58: /* masks for delimiters: blanks, fields, and termination. */
                     59: #define BLANK 1                /* ' ', '\t'; '\n' if -T is invoked */
                     60: #define FLD_D 2                /* ' ', '\t' default; from -t otherwise */
                     61: #define REC_D_F 4      /* '\n' default; from -T otherwise */
                     62:
                     63: #define min(a, b) ((a) < (b) ? (a) : (b))
                     64: #define max(a, b) ((a) > (b) ? (a) : (b))
                     65:
                     66: #define        FCLOSE(file) {                                                  \
                     67:        if (EOF == fclose(file))                                        \
                     68:                err(2, "fclose");                                       \
                     69: }
                     70:
                     71: #define        EWRITE(ptr, size, n, f) {                                       \
                     72:        if (!fwrite(ptr, size, n, f))                                   \
1.4       millert    73:                 err(2, "fwrite");                                      \
1.1       millert    74: }
                     75:
1.5       ericj      76: /* length of record is currently limited to maximum string length (size_t) */
                     77: typedef size_t length_t;
1.1       millert    78:
1.3       millert    79: #define SALIGN(n) ((n+(sizeof(length_t)-1)) & ~(sizeof(length_t)-1))
1.1       millert    80:
                     81: /* a record is a key/line pair starting at rec.data. It has a total length
                     82:  * and an offset to the start of the line half of the pair.
                     83:  */
                     84: typedef struct recheader {
                     85:        length_t length;
                     86:        length_t offset;
                     87:        u_char data[1];
                     88: } RECHEADER;
                     89:
                     90: typedef struct trecheader {
                     91:        length_t length;
                     92:        length_t offset;
                     93: } TRECHEADER;
                     94:
                     95: /* This is the column as seen by struct field.  It is used by enterfield.
                     96:  * They are matched with corresponding coldescs during initialization.
                     97:  */
                     98: struct column {
                     99:        struct coldesc *p;
                    100:        int num;
                    101:        int indent;
                    102: };
                    103:
                    104: /* a coldesc has a number and pointers to the beginning and end of the
                    105:  * corresponding column in the current line.  This is determined in enterkey.
                    106:  */
                    107: typedef struct coldesc {
                    108:        u_char *start;
                    109:        u_char *end;
                    110:        int num;
                    111: } COLDESC;
                    112:
                    113: /* A field has an initial and final column; an omitted final column
                    114:  * implies the end of the line.  Flags regulate omission of blanks and
                    115:  * numerical sorts; mask determines which characters are ignored (from -i, -d);
                    116:  * weights determines the sort weights of a character (from -f, -r).
                    117:  */
                    118: struct field {
                    119:        struct column icol;
                    120:        struct column tcol;
                    121:        u_int flags;
                    122:        u_char *mask;
                    123:        u_char *weights;
                    124: };
                    125:
                    126: union f_handle {
                    127:        int top;
                    128:        char **names;
                    129: };
                    130: extern int PANIC;      /* maximum depth of fsort before fmerge is called */
                    131: extern u_char ascii[NBINS], Rascii[NBINS], Ftable[NBINS], RFtable[NBINS];
                    132: extern u_char alltable[NBINS], dtable[NBINS], itable[NBINS];
                    133: extern u_char d_mask[NBINS];
1.7       millert   134: extern int SINGL_FLD, SEP_FLAG, UNIQUE, STABLE;
1.1       millert   135: extern int REC_D;
                    136: extern char *tmpdir;
1.4       millert   137: extern int ND;         /* limit on number of -k options. */
1.1       millert   138:
                    139: #include "extern.h"