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